<template>
    <div class="">
    <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 设备评测列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-button type="primary" round @click="urlAdd"><i class="el-icon-plus"> </i>&nbsp;&nbsp;新增评测</el-button>
            <div style="height:40px"></div>
                <el-form :inline="true"  class="demo-form-inline">
                	<el-form-item label="时间:">
                	<el-select v-model="value" placeholder="时间" @change="typechoose">
					    <el-option
					      v-for="item in options"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					  </el-select>
					 </el-form-item> 
                    <el-form-item label="设备评测标题:">
                        <el-input v-model="title" placeholder="请输入设备评测标题" clearable style="width:300px;"></el-input>
                    </el-form-item>
                    
                    <el-form-item>
                        <el-button type="primary" @click="onSelect"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                        <!-- <el-button type="primary" @click="onResetting"> &nbsp;&nbsp;重置&nbsp;&nbsp;  </el-button> -->
                    </el-form-item>
                </el-form>
                <el-table :data="tableData"  style="width: 100%"   ref="multipleTable">
                    <el-table-column prop="id" label="ID" width="100" align="center">
                    </el-table-column>
                    <el-table-column label="评测封面图" width="300" align="center">
                        <template slot-scope="scope" >
                            <div><img :src="scope.row.head_img" style="width:150px;height:100px"></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="title" label="评测标题" width="400" align="center">
                    </el-table-column>
                    <el-table-column prop="source" label="来源" width="400" align="center">
                    </el-table-column>
                    <el-table-column prop="authorize" label="认证信息" width="200" align="center">
                    </el-table-column>
                    
                    <el-table-column label="操作" align="center" >
                        <template slot-scope="scope" >
                        	<el-button class="download" size="small" type="text" @click="handleWatch(scope.$index, scope.row)">查看</el-button>
                            <el-button class="edit" size="small" type="text" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button class="del" size="small" type="text"  @click="handleDelete(scope.$index, scope.row)" >删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination" v-show="totalPages>1">
                    <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :page-size="pageSize" :total="totalElements" background>
                    </el-pagination>
                </div>
                
        </div>
        
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
        <!-- / 删除提示框 -->
    </div>
</template>
<script>
import {deviceEvaluateQuery,deviceEvaluateDelete} from '@/api/device'
export default {
    name:"deviceEvaluateList",
    data() {
        return {
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalElements:1,//默认总条数
            totalPages:1,//默认总页数
            tableData:[],//表格数据
            delIndex:0, //当前选中的下标
            delId:0,  //当前要删除的Id
            delVisible:false, //默认dialog 不弹出
            title:'',//分类标题
            type:0,
            options: [{  //分类下拉框
	          value: '0',
	          label: '所有时间'
	        }, {
	          value: '1',
	          label: '最近一个月'
	        }, {
	          value: '2',
	          label: '最近两个月'
	        }],
	        value:'所有时间'
	        }
    },
    //实例创建
    created(){
        //
        this.getList();
    },
    //计算属性
    computed:{
    	
    },
    //方法
    methods: {
    	//下拉选择分类
    	typechoose(e){
    		this.type = e;
    		this.pageIndex = 1;
			this.getList();
    	},
        //获取协会列表
        getList(){
        	var param = {
        		title:this.title,
				timeType:this.type,
				pageIndex:this.pageIndex,
				pageSize:this.pageSize
        	}
        	deviceEvaluateQuery(param).then((response) => {
                if(response.code==200){
                    var data = response.data;//当前返回的数据
                    this.tableData = data.list;//列表数据
                    this.totalElements = data.total; //总条数
                    this.totalPages = Math.ceil(data.total/this.pageSize);//总页数
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
        	})
        },
        //新增协会路由
        urlAdd(){
            this.$router.push({ path:'/device/evaluate/add'})
        },
        //查询
        onSelect(){
            this.pageIndex =1;
            this.getList();
        },
        //分页
        handleCurrentChange(val){
            this.pageIndex =val;
            this.getList();
        },
        //编辑
        handleEdit(index,row){
            if(row.id && row.id>0){
                //跳转到商品编辑
                this.$router.push({ path: '/device/evaluate/edit',query:{id:row.id}});
            }
        },
        //查看
        handleWatch(index,row){
            if(row.id && row.id>0){
                //跳转到商品编辑
                this.$router.push({ path: '/device/evaluate/watch',query:{id:row.id}});
            }
        },
        //删除
        handleDelete(index,row){
            // console.log(index,row.id);
            if(row.id && row.id>0){
                this.delIndex =index;//要删除的下标
                this.delId = row.id; //要删除的ID
                this.delVisible = true; //显示兑换弹出框
                 //console.log(this.delVisible);
            }else{
                // console.log("没触发");
            }
        },
        // 确定删除
        deleteRow(){
            //console.log(this.delId)
            if(this.delId>0){
                console.log(this.delId)
                deviceEvaluateDelete(this.delId).then(response=>{
                    console.log(response);
                    if(response.code==200){
                        this.tableData.splice(this.delIndex, 1);
                        this.$message.success('删除成功');
                        this.delVisible = false;
                    }else{
                        this.$notify.error({
                            title: '删除失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                })
            }
            
        }
        
    }
}
</script>
<style lang="stylus" scoped>
	.edit{
	    color #ff9800;
	}
	.del{
	    color #e51c23;
	}
	.download{
	    color #67C23A;
	}
</style>


